<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
class Common extends Controller
{
    public function _initialize()
    {

        

        if(!session('user_id') && $this->is_weixin()){
            header('Location:'.url('index/login/weixin'));
            exit;
        }


    	$request = Request::instance();

		$url =  strtolower($request->module()."/".$request->controller().'/'.$request->action());

    	$auth = config('auth');

    	if(in_array($url,$auth)){
    		 if(!session('user_id')){
	            $this->error('你还没有登录,请先登录!',url('index/login/index'));
	        }
    	}
    }
    public function is_weixin(){ 

    if ( strpos($_SERVER['HTTP_USER_AGENT'], 

    'MicroMessenger') !== false ) {

            return true;

        }  

            return false;

    }
}
